//
//  ActivityViewController.m
//  UI_元旦豆瓣
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "ActivityViewController.h"
#import "TableViewCell1.h"
#import "ActivityModel.h"
#import "UIImageView+WebCache.h"
#import "ActivityViewController2.h"

@interface ActivityViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray *arrDate;
@property (nonatomic, retain) NSMutableArray *modelArr;

@end

@implementation ActivityViewController

- (void)dealloc{
    [_tableView release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 green:0.4 blue:0.5 alpha:1];
    //cell 注册
    [self.tableView registerClass:[TableViewCell1 class] forCellReuseIdentifier:@"actCell"];
    // 数据解析（从activity.plist中取出数据）
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    self.arrDate = [NSArray arrayWithContentsOfFile:path];
    self.modelArr = [NSMutableArray array];
    for (NSDictionary *dic in _arrDate) {
        ActivityModel *model = [ActivityModel activitymodel];
        [model setValuesForKeysWithDictionary:dic];
        [_modelArr addObject:model];
    }
    
    
    
    
    
    
    
}
// 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _modelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableViewCell1 *cell = [[TableViewCell1 alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"actCell"];
    // 取出model
    ActivityModel *model = [ActivityModel activitymodel];
    model = _modelArr[indexPath.row];
    // 背景图片
    UIImage *imgback = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
    cell.image1.image = imgback;
    
    UIImage *imgback2 = [UIImage imageNamed:@"bg_share_large@2x.png"];
    cell.image2.image = imgback2;
    
    UIImage *imgmark = [UIImage imageNamed:@"icon_date@2x.png"];
    cell.image3.image = imgmark;
    
    UIImage *imgmark2 = [UIImage imageNamed:@"icon_spot@2x.png"];
    cell.image4.image = imgmark2;
    
    UIImage *imgmark3 = [UIImage imageNamed:@"icon_catalog@2x.png"];
    cell.image5.image = imgmark3;
    // 网络获取图片
    [cell.image6 sd_setImageWithURL:[NSURL URLWithString:model.image]];
    // 标题
    cell.lable1.text = model.title;
    // 时间
    NSString *str1 = [NSString stringWithFormat:@"%@", [model.begin_time substringWithRange:NSMakeRange(5, 11)]];
    NSString *str2 = [NSString stringWithFormat:@"%@", [model.end_time substringWithRange:NSMakeRange(5, 11)]];
    NSString *str = [NSString stringWithFormat:@"%@--%@", str1, str2];
    cell.lable2.text = str;
    // 地址
    cell.lable3.text = model.address;
    // 类型
    NSString *str3 = [NSString stringWithFormat:@"类型：%@", model.category_name];
    cell.lable4.text = str3;
    // 兴趣
    cell.lable5.text = [model.wisher_count stringValue];
    // 参加
    cell.lable6.text = [model.participant_count stringValue];
    

    return cell;
}
// 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityViewController2 *activity = [[ActivityViewController2 alloc] init];
    ActivityModel *model1 = _modelArr[indexPath.row];
    activity.model = model1;
    [self.navigationController pushViewController:activity animated:YES];

//    NSLog(@"%@", model1);
}

// 返回高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 260;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
